﻿using System.Data;

namespace Library.OrmEnterpriseEntity.TableInfo {
	///<summary>
	///</summary>
	public abstract class DbColumnView : IColumnView {
		private readonly string _columnName;
		private readonly bool _isKey;
		private readonly bool _forceHasValue;
		private readonly bool _unique;
		

		///<summary>
		///</summary>
		///<param name="columnName"></param>
		///<param name="isKey"></param>
		///<param name="forceHasValue"></param>
		///<param name="unique"></param>
		///<param name="tableView"></param>
		
		protected DbColumnView(string columnName, bool isKey, bool forceHasValue, bool unique, DbTableView tableView) {
			_columnName = columnName;
			_isKey = isKey;
			_forceHasValue = forceHasValue;
			_unique = unique;
			TableView = tableView;
			tableView.Columns.Add(this);
			ColumnIndex = tableView.Columns.Count - 1;
		}

		#region Implementation of IColumnView

		public bool ForceHasValue {
			get { return _forceHasValue; }
		}

		public bool Unique {
			get { return _unique; }
		}

		public string ColumnName {
			get { return _columnName; }
		}

		public abstract DbType DbType { get; }

		///<summary>
		///</summary>
		public int ColumnIndex { get; private set; }

		public bool IsKey {
			get { return _isKey; }
		}

		public DbTableView TableView { get; private set; }
		/// <summary>
		/// Column caption, set at create metadata instance only
		/// </summary>
		public string Caption { get; set; }

		#endregion
	}
}
